<?php require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
	require_once($GLOBALS['LIB']."/Pr_db/pr_selects.php");
	MYTCONN();

	$GET = $GLOBALS['MYT']->db_array("SELECT ntr_ID AS O_ID,
		 				ntr_Tarifa AS COL1
					FROM hd_tarifas");
	$ORI = $GLOBALS['MYT']->db_array("SELECT OriNumero AS O_ID,
		 				OriNombre AS COL2,
		 				ntr_Tarifa AS COL5,
		 				dom_RazonSocial AS COL3,
		 				OriTipo AS COL4,
		 				OriNumero AS COL1
					FROM origenes
					INNER JOIN dominios ON dom_ID = OriDominio
					INNER JOIN hd_tarifas ON OriCTRRef = ntr_ID
					WHERE OriActivo = 1");
	$CARD = $GET[0];
	$CARD1 = $ORI[0];

	 ?>



<script charset="utf-8" type="text/javascript">
disableSelection(document.getElementById("TarTab"));
Ext.onReady(function(){
    var myData = [
	<?php
	for ($i=1;$i<=$CARD;$i++) {
	echo '['.$i.','.$GET[$i]['O_ID'].',\''.$GET[$i]['COL1'].'\']';
		if ($i<$CARD) {
			echo ',';
	}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'O_ID', type: 'int'},
               {name: 'COL1', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
		{header: "N", width: 60, sortable: true, locked:true, dataIndex: 'O_ID'},
		{header: "Tarifa", width: 200, sortable: true, locked:true, dataIndex: 'COL1'}
    ]);


   Bars = new Ext.Toolbar({

					store: this.store,
					height: 25,
					align: 'right',
					items : [ {text: "Aplicar a Selecionados"} ]
				});

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
   			title: 'Tarifas Em Vigor',
	        ds: ds,
	            cm: colModel,
	            sm: selmode,
				listeners: {
					rowclick: function(ds, row) {
					var record = ds.getStore().getAt(row);
  					var value = record.get('O_ID');
					replaceUrl('Tars_Detail','Modules/FTK9D4D0/Lib/tars_def/elem_tars.mex?TID='+value);
					}
				},
	            height: 600,
				bbar: Bars,
				renderTo: 'TarTab'
    });

});
disableSelection(document.getElementById("OriTab"));
Ext.onReady(function(){
    var myData = [
	<?php
	for ($i=1;$i<=$CARD1;$i++) {
	echo '['.$i.','.$ORI[$i]['O_ID'].',\''.$ORI[$i]['COL1'].'\',\''.$ORI[$i]['COL2'].'\',\''.$ORI[$i]['COL3'].'\',\''.$ORI[$i]['COL4'].'\',\''.$ORI[$i]['COL5'].'\']';
		if ($i<$CARD1) {
			echo ',';
		}
    } ?>
    ];

    var ds = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'id'},
			   {name: 'O_ID', type: 'int'},
               {name: 'COL1', type: 'string'},
               {name: 'COL2', type: 'string'},
               {name: 'COL3', type: 'string'},
               {name: 'COL4', type: 'string'},
               {name: 'COL5', type: 'string'}
          ])
    });
    ds.loadData(myData);
    var colModel = new Ext.grid.ColumnModel([
		{header: "N", width: 60, sortable: true, locked:true, dataIndex: 'O_ID'},
		{header: "Numero", width: 50, sortable: true, locked:true, dataIndex: 'COL1'},
		{header: "Origen", width: 200, sortable: true, locked:true, dataIndex: 'COL2'},
		{header: "Dominio", width: 200, sortable: true, locked:true, dataIndex: 'COL3'},
		{header: "Tipo", width: 120, sortable: true, locked:true, dataIndex: 'COL4'},
		{header: "Tarifa", width: 120, sortable: true, locked:true, dataIndex: 'COL5'}
    ]);


   Bars = new Ext.Toolbar({

					store: this.store,
					height: 25,
					align: 'right',
					items : [ {text: "Aplicar a Selecionados"} ]
				});

   var selmode = new Ext.grid.RowSelectionModel({});
   var Console = new Ext.grid.GridPanel({
   			title: 'Origens Activas',
	        ds: ds,
	            cm: colModel,
	            sm: selmode,
				listeners: {
					rowclick: function(ds, row) {
					var record = ds.getStore().getAt(row);
  					var value = record.get('O_ID');
					replaceUrl('Tars_Detail','Modules/FTK9D4D0/Lib/tars_def/elem_tars.mex?TID='+value);
					}
				},
	            height: 600,
				bbar: Bars,
				renderTo: 'OriTab'
    });

});
</script>
<div class="title">Aplicar Tarifas</div>
<div id="TarTab" style="width:18%;float:left"></div>
<div id="OriTab" style="width:80%;float:right"></div>